package TreeMap;



import java.util.Comparator;
import java.util.TreeMap;

public class Test2 {
    public static void main(String[] args) {
        TreeMap<Student,String> tm=new TreeMap<>(new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                int i=o1.getAge()-o2.getAge();
                i=i==0?o1.getName().compareTo(o2.getName()):i;
                return i;
            }
        });
        //创建学生对象
        Student s1=new Student("zhangsan",18);
        Student s2=new Student("lisi",19);
        Student s3=new Student("wangwu",20);
        Student s4=new Student("wangwu",20);


        //添加元素
        tm.put(s1,"guangdong");
        tm.put(s2,"jiangxi");
        tm.put(s3,"anhui");
        tm.put(s4,"guangxi");


        System.out.println(tm);
    }
}
